<?php
namespace App\Model;
use App\Repository\Sys\Db;
use App\Repository\Common\ConstTable;
use App\Repository\Sys\JsonRespose;
use App\Repository\Sys\Str;
use EasyWeChat\Support\Log;

class UserLevelSetTable{
    use Db;
    static private $table = 'user_level_set';

    static public function updateLevel($uid,$integral){
        $integral_res = UserLevelSetTable::ORM()->where('start_integral', '<=', $integral)->where('end_integral', '>=', $integral)->orderBy('start_integral', 'desc')->first();

        if ($integral_res) {
            $user = UserTable::ORM()->where('id', $uid)->update([
                'integral' => $integral,
                'vip' => $integral_res->level_name,
                'vip_level_id' => $integral_res->id,
            ]);  //  一块钱1积分
            if (!$user) {
                Log::error('更新订单用户数据失败');
            }
        }
    }
}